package com.jy.borrowrecords.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jy.common.annotation.Log;
import com.jy.common.core.controller.BaseController;
import com.jy.common.core.domain.AjaxResult;
import com.jy.common.enums.BusinessType;
import com.jy.borrowrecords.domain.Borrowrecords;
import com.jy.borrowrecords.service.IBorrowrecordsService;
import com.jy.common.utils.poi.ExcelUtil;
import com.jy.common.core.page.TableDataInfo;

/**
 * 图书借阅记录Controller
 * 
 * @author ruoyi
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/borrowrecords/borrowrecords")
public class BorrowrecordsController extends BaseController
{
    @Autowired
    private IBorrowrecordsService borrowrecordsService;

    /**
     * 查询图书借阅记录列表
     */
    @PreAuthorize("@ss.hasPermi('borrowrecords:borrowrecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(Borrowrecords borrowrecords)
    {
        startPage();
        List<Borrowrecords> list = borrowrecordsService.selectBorrowrecordsList(borrowrecords);
        return getDataTable(list);
    }

    /**
     * 导出图书借阅记录列表
     */
    @PreAuthorize("@ss.hasPermi('borrowrecords:borrowrecords:export')")
    @Log(title = "图书借阅记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Borrowrecords borrowrecords)
    {
        List<Borrowrecords> list = borrowrecordsService.selectBorrowrecordsList(borrowrecords);
        ExcelUtil<Borrowrecords> util = new ExcelUtil<Borrowrecords>(Borrowrecords.class);
        util.exportExcel(response, list, "图书借阅记录数据");
    }

    /**
     * 获取图书借阅记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('borrowrecords:borrowrecords:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(borrowrecordsService.selectBorrowrecordsByRecordId(recordId));
    }

    /**
     * 新增图书借阅记录
     */
    @PreAuthorize("@ss.hasPermi('borrowrecords:borrowrecords:add')")
    @Log(title = "图书借阅记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Borrowrecords borrowrecords)
    {
        return toAjax(borrowrecordsService.insertBorrowrecords(borrowrecords));
    }

    /**
     * 修改图书借阅记录
     */
    @PreAuthorize("@ss.hasPermi('borrowrecords:borrowrecords:edit')")
    @Log(title = "图书借阅记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Borrowrecords borrowrecords)
    {
        return toAjax(borrowrecordsService.updateBorrowrecords(borrowrecords));
    }

    /**
     * 删除图书借阅记录
     */
    @PreAuthorize("@ss.hasPermi('borrowrecords:borrowrecords:remove')")
    @Log(title = "图书借阅记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(borrowrecordsService.deleteBorrowrecordsByRecordIds(recordIds));
    }
}
